/*
 * createModes.cpp
 *
 *  Created on: 13/02/2014
 *      Author: mattia
 */

#include "signatures.h"
#include <stdlib.h>
#include <time.h>

int selectFromDiscreteUniformDestribution(int from, int to);
float selectFromUniformDestribution(float from, float to);

int createModes(int n, int * M, int ** times, int ** costs){

	for (int i = 0; i < n; i++){

		M[i] = selectFromDiscreteUniformDestribution(1, 10);

		times[i] = new int[M[i]];
		costs[i] = new int[M[i]];

		for (int j = 0; j < M[i]; j++){

			times[i][j] = selectFromDiscreteUniformDestribution(3, 123);

			int swapAux;

			// Insertar burbuja en times[i] de modo que quede ordenado
			for (int k = j; (k > 0) && (times[i][k - 1] < times[i][k]); k--){

				swapAux = times[i][k - 1];
				times[i][k - 1] = times[i][k];
				times[i][k] = swapAux;

			}

		}

		costs[i][0] = selectFromDiscreteUniformDestribution(5, 15);

		for (int j = 1; j < M[i]; j++){

			float alpha = selectFromUniformDestribution(0, 1);
			costs[i][j] = costs[i][j-1] + alpha * (times[i][j-1] - times[i][j]);

		}

	}

	return 0;
}

/*int selectFromDiscreteUniformDestribution(int from, int to){
	return from + rand() % ((to - from) + 1);
}*/

float selectFromUniformDestribution(float from, float to){
	return from + (((float)rand()) / ((float) RAND_MAX)) * (to - from);
}
